home *** CD-ROM | disk | FTP | other *** search
/ Maclife 40 / MACLIFE40.ISO.7z / MACLIFE40.ISO / MACLIFE連載 / 特集II DTPデザインを効率化 / AppleScript⁄サンプル / SampleScript / For OtherApplication / 平凡な毎日_folder / 平凡な毎日.src < prev   
Text File  |  1998-05-16  |  7KB  |  272 lines

  1. global YOUBI_LIST, FF, ANS, HARU, AKI
  2.  
  3. with timeout of 3600 seconds
  4.     repeat --入力がされるまでくりかえす
  5.         set ANS to text returned of (display dialog "カレンダーを作成する場合は西暦年を
  6. 曜日が知りたい場合は日付まで入力してください。
  7. ex.) 1998
  8.     1998.5.5" default answer "1998" with icon 1)
  9.         if ANS is not "" then exit repeat
  10.     end repeat
  11. end timeout
  12.  
  13.  
  14. try --なにが入力されているかわからないんで
  15.     --入力を分割
  16.     set TID to AppleScript's text item delimiters
  17.     set AppleScript's text item delimiters to {"."}
  18.     set ANS_1 to every text item of ANS
  19.     set AppleScript's text item delimiters to TID
  20.     
  21.     
  22.     --カレンダー作成
  23.     if length of (ANS_1) = 1 then
  24.         with timeout of 3600 seconds
  25.             set new_file to new file with prompt "どこに保存しますか?" default name (ANS as string)
  26.         end timeout
  27.         --この年は何曜日から始まるのか(システム依存)
  28.         set YOUBI to weekday of (date (item 1 of ANS_1 & ".1.1"))
  29.         --この年は閏年か?(この計算では、2100年の閏年にならない年を計算できない)
  30.         if (ANS mod 4) is 0 then
  31.             set URU to true
  32.         else
  33.             set URU to false
  34.         end if
  35.         
  36.         --カレンダーの作成はサブルーチンにおまかせ
  37.         set CALENDER to ANS & "年カレンダー" & return & return
  38.         set CALENDER to my make_CALENDER(CALENDER, YOUBI, URU)
  39.         --ファイル書き込み
  40.         set FH to open for access new_file with write permission
  41.         try
  42.             write CALENDER to FH
  43.         on error errMsg number ERRNO
  44.             close access FH
  45.             display dialog "書き込みエラーが発生しました" & return & errMsg & ERRNO
  46.             return
  47.         end try
  48.         close access FH
  49.         
  50.         display dialog "正常に書き込まれました。
  51. ただし、春分・秋分の日(およびその振替休日)は簡易計算によるものです。正確には前年の2月1日付の官報で決定されますのでそちらも参照してください。" with icon 1
  52.         
  53.         
  54.         
  55.         
  56.         --今日は何の日?データーベース
  57.     else if (length of ANS_1) = 2 then
  58.         display dialog "今日は何の日?データーベースは次期バージョンでサポートです。ごめんなさい。" with icon 1
  59.         
  60.         
  61.         
  62.         
  63.         --曜日計算(将来的に六曜もサポートしたい...)
  64.     else if (length of ANS_1) = 3 then
  65.         set YOUBI to weekday of (date ANS) --(システム依存)
  66.         set YOUBI to my make_YOUBI(YOUBI)
  67.         display dialog ANS & ";" & YOUBI & "曜日" with icon1
  68.         
  69.         
  70.         --入力違い
  71.     else
  72.         display dialog "たぶん入力を間違えています。
  73. 数字もピリオドも半角で、余分なスペースは入れないでください。" with icon 2
  74.     end if
  75.     
  76.     
  77.     --エラー処理
  78. on error errMsg number ERRNO
  79.     display dialog "たぶん入力を間違えています。
  80. 数字もピリオドも半角で、余分なスペースは入れないでください。
  81. " & "errNO. " & ERRNO & return & errMsg with icon 2
  82. end try
  83.  
  84.  
  85.  
  86.  
  87.  
  88.  
  89. --●曜日換算
  90. ------------------------------------------------------------------------------------
  91. on make_YOUBI(YOUBI)
  92.     if YOUBI = Sunday then
  93.         set YOUBI to "日"
  94.     else if YOUBI = Monday then
  95.         set YOUBI to "月"
  96.     else if YOUBI = Tuesday then
  97.         set YOUBI to "火"
  98.     else if YOUBI = Wednesday then
  99.         set YOUBI to "水"
  100.     else if YOUBI = Thursday then
  101.         set YOUBI to "木"
  102.     else if YOUBI = Friday then
  103.         set YOUBI to "金"
  104.     else if YOUBI = Saturday then
  105.         set YOUBI to "土"
  106.     end if
  107.     
  108.     --これじゃだめじゃった...
  109.     --set aa to {Sunday:{1, 日}, Monday:{2, 月}, Tuesday:{3, 火}, Wednesday:{4, 水}, Thursday:{5, 木}, Friday:{6, 金}, Saturday:{7, 土}}
  110.     --set YOUBI to item 2 of YOUBI of aa
  111.     
  112.     return YOUBI
  113. end make_YOUBI
  114.  
  115.  
  116.  
  117.  
  118.  
  119. --●カレンダー作成
  120. ------------------------------------------------------------------------------------
  121. on make_CALENDER(CALENDER, YOUBI, URU)
  122.     
  123.     --元旦の曜日を数字に変換(こんなやり方しかないとは...とほほ)
  124.     if YOUBI = Sunday then
  125.         set YOUBI to 1
  126.     else if YOUBI = Monday then
  127.         set YOUBI to 2
  128.     else if YOUBI = Tuesday then
  129.         set YOUBI to 3
  130.     else if YOUBI = Wednesday then
  131.         set YOUBI to 4
  132.     else if YOUBI = Thursday then
  133.         set YOUBI to 5
  134.     else if YOUBI = Friday then
  135.         set YOUBI to 6
  136.     else if YOUBI = Saturday then
  137.         set YOUBI to 7
  138.     end if
  139.     --そいでこのリストと対比させる(グローバル変数)
  140.     global YOUBI_LIST
  141.     set YOUBI_LIST to {"(日)", "(月)", "(火)", "(水)", "(木)", "(金)", "(土)"}
  142.     
  143.  
  144. --春分・秋分の日計算(これはあくまで簡易計算です。しかも1900≦西暦≦2099)
  145. set HARU to (0.24242 * ANS - (ANS div 4) + 35.84) div 1
  146. set AKI to (0.24204 * ANS - (ANS div 4) + 39.01) div 1
  147.  
  148.  
  149.     
  150.     --ここから作成(でも実際はKEISAN()が仕事してます)
  151.     repeat with TUKI from 1 to 12
  152.         if TUKI = 1 or TUKI = 3 or TUKI = 5 or TUKI = 7 or TUKI = 8 or TUKI = 10 or TUKI = 12 then --大の月 31 日まで
  153.             repeat with NITI from 1 to 31
  154.                 set CALENDER to my KEISAN(CALENDER, TUKI, NITI, YOUBI)
  155.                 set YOUBI to my YOUBI_kasan(YOUBI)
  156.             end repeat
  157.             
  158.         else if TUKI = 2 and URU = true then --閏年の2月
  159.             repeat with NITI from 1 to 29
  160.                 set CALENDER to my KEISAN(CALENDER, TUKI, NITI, YOUBI)
  161.                 set YOUBI to my YOUBI_kasan(YOUBI)
  162.             end repeat
  163.             
  164.         else if TUKI = 2 and URU = false then --普通の2月
  165.             repeat with NITI from 1 to 28
  166.                 set CALENDER to my KEISAN(CALENDER, TUKI, NITI, YOUBI)
  167.                 set YOUBI to my YOUBI_kasan(YOUBI)
  168.             end repeat
  169.             
  170.         else if TUKI = 4 or TUKI = 6 or TUKI = 9 or TUKI = 11 then --小の月 30 日まで
  171.             repeat with NITI from 1 to 30
  172.                 set CALENDER to my KEISAN(CALENDER, TUKI, NITI, YOUBI)
  173.                 set YOUBI to my YOUBI_kasan(YOUBI)
  174.             end repeat
  175.             
  176.         end if
  177.     end repeat
  178.     return CALENDER
  179.     
  180. end make_CALENDER
  181.  
  182.  
  183.  
  184.  
  185. --●曜日・祝日・振替えの計算
  186. ------------------------------------------------------------------------------------
  187. on KEISAN(CALENDER, TUKI, NITI, YOUBI)
  188.     
  189.     --祝祭日(春分・秋分は簡易計算に基づく)
  190.     if TUKI = 1 and NITI = 1 then
  191.         set IWAI to "元旦"
  192.         set F to 0 --振り替え休日なし
  193.     else if TUKI = 1 and NITI = 15 then
  194.         set IWAI to "成人の日"
  195.         set F to 1 --振り替え休日あり
  196.     else if TUKI = 2 and NITI = 11 then
  197.         set IWAI to "建国記念日"
  198.         set F to 1
  199.     else if TUKI = 3 and NITI = HARU then
  200.         set IWAI to "春分の日"
  201.         set F to 1
  202.     else if TUKI = 4 and NITI = 29 then
  203.         set IWAI to "緑の日"
  204.         set F to 1
  205.     else if TUKI = 5 and NITI = 3 then
  206.         set IWAI to "憲法記念日"
  207.         set F to 1
  208.     else if TUKI = 5 and NITI = 5 then
  209.         set IWAI to "こどもの日"
  210.         set F to 1
  211.     else if TUKI = 7 and NITI = 20 then
  212.         set IWAI to "海の日"
  213.         set F to 1
  214.     else if TUKI = 9 and NITI = 15 then
  215.         set IWAI to "敬老の日"
  216.         set F to 1
  217.     else if TUKI = 9 and NITI = AKI then
  218.         set IWAI to "秋分の日"
  219.         set F to 1
  220.     else if TUKI = 10 and NITI = 10 then
  221.         set IWAI to "体育の日"
  222.         set F to 1
  223.     else if TUKI = 11 and NITI = 3 then
  224.         set IWAI to "文化の日"
  225.         set F to 1
  226.     else if TUKI = 11 and NITI = 23 then
  227.         set IWAI to "勤労感謝の日"
  228.         set F to 1
  229.     else if TUKI = 12 and NITI = 23 then
  230.         set IWAI to "天皇誕生日"
  231.         set F to 1
  232.     else
  233.         set IWAI to ""
  234.         set F to 0
  235.     end if
  236.     
  237.     
  238.     --振り替え休日
  239.     global FF
  240.     if YOUBI = 1 and F = 1 then --日曜日に休日
  241.         set FF to 2
  242.     else if YOUBI = 2 and FF = 1 then --その次の日(振り替え)
  243.         set IWAI to "振替休日"
  244.     else
  245.         set FF to 0
  246.     end if
  247.     
  248.     --変数CALENDERへの書き込み
  249.     set CALENDER to CALENDER & TUKI & "月" & NITI & "日" & item YOUBI of YOUBI_LIST & IWAI & return
  250.     
  251.     --振替休日のフラッグを減じる
  252.     set FF to FF - 1
  253.     
  254.     
  255.     return CALENDER
  256. end KEISAN
  257.  
  258.  
  259.  
  260.  
  261.  
  262. --●曜日の加算
  263. ------------------------------------------------------------------------------------
  264. on YOUBI_kasan(YOUBI)
  265.     --曜日の加算
  266.     if YOUBI = 7 then
  267.         set YOUBI to YOUBI - 6
  268.     else
  269.         set YOUBI to YOUBI + 1
  270.     end if
  271.     return YOUBI
  272. end YOUBI_kasan